package s2elinshu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

// ctrl+shift+O를 누르면 자동 import

public class J24ProfessorDAOImpl implements J24ProfessorDAO {

	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	private static String URL = "jdbc:oracle:thin:s2elinshu/s2elinshu@112.216.253.124:1521:xe";
	private static String insertSQL = "  ";
	private static String selectSQL = " select * from professor order by pfno ";
	private static String selectOneSQL = "  ";
	private static String updateSQL = "  ";
	private static String deleteSQL = "  ";

	@Override
	public String[] insertProfessor(J24ProfessorVO pvo) {

		return null;
	}

	@Override
	public ArrayList<J24ProfessorVO> selectProfessor() {
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<J24ProfessorVO> pvoes = null;
		try {
			conn = makeConn();
			pstmt = conn.prepareStatement(selectSQL);
			rs = pstmt.executeQuery();
			
			pvoes = new ArrayList<>();
			while(rs.next()){
				J24ProfessorVO vo = new J24ProfessorVO();
				vo.setPfno(rs.getString(1));
				vo.setPfname(rs.getString(2));
				vo.setFields(rs.getString(3));
				vo.setSkills(rs.getString(4));
				vo.setRegdate(rs.getString(5));
				
				pvoes.add(vo);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			closeConn(conn, pstmt, rs);
		}

		return pvoes;
	}

	private void closeConn(Connection c, PreparedStatement p,
			ResultSet r) {
		if(r != null)try {r.close();			
		} catch (Exception e) {
		}
		if(p != null)try {p.close();			
		} catch (Exception e) {
		}
		if(c != null)try {c.close();			
		} catch (Exception e) {
		}
	}

	private Connection makeConn() 	throws Exception{
		Connection conn = null;
	    Class.forName(DRV);
		conn = DriverManager.getConnection(URL);
		return conn;
		
	}

	@Override
	public ArrayList<J24ProfessorVO> selectOneProfessor(String pfno) {

		return null;
	}

	@Override
	public String[] updateProfessor(String pfno) {

		return null;
	}

	@Override
	public String[] deleteProfessor(String pfno) {

		return null;
	}

}
